package com.datang.pet.api.attentionController;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-06-14 15:28
 * @notify
 * @version 1.0
 */

import com.datang.pet.common.response.Result;
import com.datang.pet.common.utils.MD5;
import com.datang.pet.common.utils.StringUtils;
import com.datang.pet.service.AttentionService;
import com.datang.pet.vo.AddAttentionRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AddAttentionController {

    @Autowired
    private AttentionService attentionService;

    @PostMapping("/addAttention")
    public Result addAttention(@RequestBody AddAttentionRequest addAttentionRequest) throws Exception {
        //UserId是否为空
        if (!StringUtils.isNUll(addAttentionRequest.getUserId())) {
            throw new Exception("关注人id为空");
        }
        //UserId是否为空
        if (!StringUtils.isNUll(addAttentionRequest.getFansId())) {
            throw new Exception("你的id为空");
        }
        //UserId是否为空
        if (!StringUtils.isNUll(addAttentionRequest.getType())) {
            throw new Exception("没有类型");
        }

        //md5解密userId(普通用户)
        try {
            addAttentionRequest.setFansId(MD5.decryptData(addAttentionRequest.getFansId()));
        } catch (Exception e) {
            throw new Exception("fansId解密出错！");
        }
        attentionService.addAttention(addAttentionRequest);

        return Result.ok("成功");
    }
}
